package at.htlkaindorf.jsf.application;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import at.htlkaindorf.jsf.domain.Entry;

/**
 * @author david.tomes
 */
@ManagedBean(name = "dataBean")
@ApplicationScoped
public class DataBean implements Serializable {

    private static final long serialVersionUID = 4352215871073435967L;

    private List<Entry> guestbookEntries = new ArrayList<Entry>();

    private Long currentId = 0L;

    public DataBean() {
        addTestEnries();
    }

    private void addTestEnries() {
        Date now = new Date();
        guestbookEntries.add(new Entry(currentId++, "Arno", "arno@infonova.com", new Date(now.getTime() - 6000), "Re: JSF 2.2 Forum", "Wooohoooo :D"));
        guestbookEntries.add(new Entry(currentId++, "David", "david@infonova.com", new Date(now.getTime() - 12000), "Re: JSF 2.2 Forum", "Viel Spass! :)"));
        guestbookEntries.add(new Entry(currentId++, "Christian", "christian@infonova.com", new Date(now.getTime() - 18000), "JSF 2.2 Forum", "Das ist ein JSF Testforum."));
    }

    public List<Entry> getGuestbookEntries() {
        return guestbookEntries;
    }

    public void setGuestbookEntries(List<Entry> guestbookEntries) {
        this.guestbookEntries = guestbookEntries;
    }

    public void addGuestBookEntry(String name, String email, String title, String text) {
        guestbookEntries.add(new Entry(currentId++, name, email, new Date(), title, text));
    }
}
